package com.yingsheng.bi.hks.service.merch;

import com.yingsheng.bi.hks.basic.PUser;
import com.yingsheng.bi.hks.basic.utils.Subject;
import com.yingsheng.bi.hks.bo.MerchBo;
import com.yingsheng.bi.hks.dto.merch.*;
import com.yingsheng.bi.hks.mapping.MerchMgmtMappings;
import com.yingsheng.bi.hks.repository.dao.po.Merchants;
import com.yingsheng.bi.hks.repository.dao.service.MerchDaoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class MerchMgmtService {

    @Autowired
    private MerchDaoService merchDaoService;

    /**
     * 商户新增
     * @param req
     * @return
     */
    public MerchAddRes add(MerchAddReq req) {
        Merchants merchants = MerchMgmtMappings.INSTANCE.addReq2po(req);
        merchDaoService.insert(merchants);
        return new MerchAddRes();
    }

    /**
     * 商户删除
     * @param req
     * @return
     */
    public MerchDelRes del(MerchDelReq req) {
        merchDaoService.del(req.getId());
        MerchDelRes merchDelRes = new MerchDelRes();
        return merchDelRes;
    }

    /**
     * 商户修改
     * @param req
     * @return
     */
    public MerchModRes mod(MerchModReq req) {
        Merchants merchants = MerchMgmtMappings.INSTANCE.addReq2po(req);
        merchDaoService.updateById(merchants);
        return new MerchModRes();
    }

    /**
     * 商户查询
     * @param req
     * @return
     */
    public MerchQryRes qry(MerchQryReq req) {
        PUser user = Subject.get();
        List<Merchants> list = merchDaoService.query(req.getOwnerId());
        List<MerchBo> addrList = MerchMgmtMappings.INSTANCE.merchList2boList(list);
        MerchQryRes res = new MerchQryRes();
        res.setMerchBoList(addrList);
        return res;
    }
}
